
package cn.logicalthing.demo.web.controller;

import com.core.vo.ShipmentsVO;
import cn.logicalthing.demo.web.error.CommonErrorCode;
import cn.logicalthing.demo.web.error.RequestBean;
import com.core.bean.Goods;
import com.core.dao.jdbcmysql.ShipmentsDao;
import com.core.dao.mybatismysql.GoodsDao;
import com.core.service.ShipmentsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ShipmentsController {

    /**
     * 添加发货
     *
     * @param shipmentsVO
     * @return
     */
    @PostMapping("/addShipments")
    public RequestBean add(ShipmentsVO shipmentsVO) {
        if (shipmentsVO == null) {
            return new RequestBean(CommonErrorCode.E_3002);
        }
        try {
            int add = new ShipmentsService().add(shipmentsVO);
            if (add <= 0) {
                return new RequestBean(CommonErrorCode.E_3001);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new RequestBean(CommonErrorCode.E_9999);
        }
        return new RequestBean("添加成功!");
    }

    /**
     * 拒接签收
     *
     * @param id 发货单ID
     * @return
     */
    @PostMapping("id")
    public RequestBean Reject(String id) {
        if (id == null || id.length() == 0) {
            return new RequestBean(CommonErrorCode.E_3002);
        }
        try {
            int num = new ShipmentsService().Reject(id);
            if (num <= 0) {
                return new RequestBean(CommonErrorCode.E_3004);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new RequestBean(CommonErrorCode.E_3003);
        }
        return new RequestBean("拒接成功");
    }

    /**
     * 确认收货
     *
     * @param id 发货单id
     * @return
     */
    @PostMapping("/confirmShipments")
    public RequestBean confirm(String id) {
        if (id == null || id.length() == 0) {
            return new RequestBean(CommonErrorCode.E_3002);
        }
        try {
            int num = new ShipmentsService().confirm(id);
            if (num <= 0) {
                return new RequestBean(CommonErrorCode.E_3005);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new RequestBean(CommonErrorCode.E_3005);
        }
        return new RequestBean("确认成功!");
    }

}
